package com.example.demo.sys.service.impl;

import com.example.demo.sys.dao.SysUser;
import com.example.demo.sys.mapper.SysUserMapper;
import com.example.demo.sys.service.SysUserService;
import com.example.demo.system.utility.PageInfo;
import com.example.demo.system.utility.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    //列表查询
    @Override
    public Result getList(Integer pageNum, Integer pageSize, String name){
        Integer start = PageInfo.start(pageNum,pageSize);
        List<SysUser> list = sysUserMapper.getList(start, pageSize, name);
        Integer listCount = sysUserMapper.getListCount(name);
        PageInfo info = new PageInfo(pageNum, pageSize, listCount, list);
        return Result.success(info);
    }

    @Override
    public SysUser get(Integer id){
        return sysUserMapper.get(id);
    }

    @Override
    public Result add(SysUser sysUser) {
        sysUser.setModifeTime(new Date());
        sysUserMapper.add(sysUser);
        return Result.success("新增成功");
    }
    @Override
    public Result update(SysUser sysUser) {
        sysUser.setModifeTime(new Date());
        sysUserMapper.update(sysUser);
        return Result.success("修改成功");
    }

    @Override
    public Result delete(Integer id) {
        sysUserMapper.delete(id);
        return Result.success("删除成功");
    }
}
